package pdfsetter.core.schema.advanced;

import java.util.ArrayList;
import java.util.List;

import pdfsetter.core.schema.FillingSchema;

/**
 * This is automatic version of {@link RepetitiveFileListProcessPattern}. We select pages from every file in the same way (the same {@link FilePageSelector})
 * and we mixed the selections - i.e. we take first pages from all files, than second pages and so on. We do it in the same way as in
 * {@link RepetitiveFileListProcessPattern} and when we have to take page from outside the selectino we simply take blank page.
 * 
 * @author Andrzej Dorobisz
 */
public class AutomaticRepetitiveProcessPattern implements FillingSchemaPattern {
    private final FilePageSelector selector;

    public AutomaticRepetitiveProcessPattern(FilePageSelector selector) {
        this.selector = selector;
    }

    @Override
    public FillingSchema produceFillingSchema(int[] fileSizes) {
        List<AttachedFilePageSelector> attachedSelectors = new ArrayList<AttachedFilePageSelector>(fileSizes.length);
        for (int fileNum = 0; fileNum < fileSizes.length; fileNum++) {
            attachedSelectors.add(new AttachedFilePageSelector(selector, fileNum));
        }
        return new RepetitiveFileListProcessPattern(attachedSelectors).produceFillingSchema(fileSizes);
    }

    @Override
    public int getExpectedNumberOfFiles() {
        return -1;
    }
}